import React, {Component} from 'react'
import {inject, observer} from 'mobx-react';
import {Tabs, Spin} from 'antd'
import Comment from './rightContainer/index'
import { WeaLocaleProvider } from 'ecCom'
const TabPane = Tabs.TabPane
const getLabel = WeaLocaleProvider.getLabel;

@inject('checkMatterStore')
@observer
class CommentMain extends Component {

    constructor(props) {
        super(props);
        this.state = {...this.initData()}
        this.getWeiboListByAction = this.getWeiboListByAction.bind(this);
    }

    initData = () => {
        return {
            startSearch: false,
            searching: false,
            searchForm: {},
            weiboType: 1,
            weiboGroup: "all"
        }
    }
    get currentGroup() {
        return this.state.weiboGroup
    }

    set clear(value) {
        if(value) this.setState({...this.initData()})
    }

    render() {
        let {isEndPage} = this.props.checkMatterStore
        let { userInfo, weiboCKEditorConfig, weiboGroup, weiboList,  topHeight, systemWorkLog, fanList,
                basicInfo: {countData = {}},
                attentionList, checkAttention, changeGroup, defaultTemplate, loading, keyWords,tab,comment,showSlideEdit,defaultHeight} = this.props,
            {weiboType, startSearch} = this.state,
            containerHeight = topHeight - 120,
            commonProps = {
                userInfo: userInfo,
                height: containerHeight,
                systemWorkLog: systemWorkLog,
                //isReset: startSearch,
                defaultTemplate: defaultTemplate.defaultTemplate || {},
                weiboCKEditorConfig: weiboCKEditorConfig.appList
            },
            //审批意见、评论
            weibos = [
                {id: 1, type: 21, name: getLabel(26467,tab[0]), data: weiboList, others: commonProps, hasScroll: true, hasEditor: true,hasImage:true},
            ];
            let isPageEnd = isEndPage();
        return (
            <div className="g-comment-main">
                {
                    <Tabs ecId={`${this && this.props && this.props.ecId || ''}_Tabs@pjeghm`}
                        animation={false}
                        activeKey={weiboType+""}
                        size="default"
                        //onChange={this.changeWeiboType.bind(this, weibos)}
                    >
                        {this.getTabsDom( weibos, loading, keyWords,comment,isPageEnd,showSlideEdit,defaultHeight)}
                    </Tabs>
                }
            </div>
        )
    }
    getTabsDom = ( tabs, loading, keyWords,comment,isPageEnd,showSlideEdit,defaultHeight) => {
        return tabs.map(
            (item, key) => {
                let {id, group, type, name, data, others, hasScroll, hasEditor, hasImage,commentCount} = item,
                    hasData = data.discussList && data.discussList.length > 0 , end = !data.__hasData,
                    topHeight = this.props.topHeight - 61;
                   
                return (
                    <TabPane ecId={`${this && this.props && this.props.ecId || ''}_TabPane@x9p6w8@${id}`}
                        tab={
                                <div>
                                    <span title={name.split('').length>10?name:''}>{name}</span>
                                    {commentCount ? <span className="g-tip">{`(${commentCount})`}</span> : undefined}
                                </div>
                        }
                        key={id}
                    >

                            <div className="g-comment">
                                <Comment ecId={`${this && this.props && this.props.ecId || ''}_Comment@likvx5@${id}`}
                                    {...others}
                                    records={data}
                                    hasScroll={hasScroll || false}
                                    hasEditor={hasEditor || false}
                                    hasImage={hasImage || false}
                                    keyWords={keyWords}
                                    topHeight={topHeight}
                                    loading={loading}
                                    comment={comment}
                                    showSlideEdit={showSlideEdit}
                                    defaultHeight={defaultHeight}
                                />
                                {hasData && loading && <div className="g-align-center g-pt10"><Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@oezog3@${id}`} tip={getLabel(384399,"加载中，请稍候...")}/></div>}
                            </div>
                           {/*  { isPageEnd && !loading  &&  <div className="g-align-center g-pt10">{getLabel(384398,"没有审批意见了")}</div>} */}
                    </TabPane>
                )
            }
        )
    }
    getWeiboListByAction(others, params) {
        let {getWeiboList} = this.props.checkMatterStore;
        getWeiboList(others, params)
    }
    searchWeiboListByAction(params) {
        let {searchWeiboList} = this.props.checkMatterStore;
        searchWeiboList(params);
    }
    searchWeiboMainPageListByAction(params) {
        let {searchWeiboMainPageList} = this.props.checkMatterStore;
        searchWeiboMainPageList(params);
    }

}

export default CommentMain
